package ${servicePackageName}.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.github.pagehelper.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;
import ${servicePackageName}.bean.${className}Bean;
import ${servicePackageName}.repository.${className}Mapper;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.github.pagehelper.PageHelper;

/**
* 描述：${className}Service 服务接口
* @author ${author}
* @date ${date}
*/

@EnablePaasMybatis
@MapperScan("${servicePackageName}.repository")
@Service
public class ${className}Service extends BaseDao<${className}Bean, ${className}Mapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return ${className}Mapper.class.getName();
		}
		
		@Autowired
		private ${className}Mapper ${className?uncap_first}Mapper;
		
		public PaginationEntity<${className}Bean> getPage${className}List(BasePage pageRequest, ${className}Bean ${className?uncap_first}Bean) {
			Page<${className}Bean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true, false);
			List<${className}Bean> list = ${className?uncap_first}Mapper.getList(${className?uncap_first}Bean);
			PaginationEntity<${className}Bean> paginationEntity = new PaginationEntity<${className}Bean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean save${className}(${className}Bean ${className?uncap_first}Bean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = ${className?uncap_first}Mapper.insert${className}(${className?uncap_first}Bean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean update${className}(${className}Bean ${className?uncap_first}Bean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = ${className?uncap_first}Mapper.update${className}(${className?uncap_first}Bean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public ${className}Bean get${className}Detail(String id) {
			return ${className?uncap_first}Mapper.get${className}Detail(id);
		}
		
		public boolean delete${className}(${className}Bean ${className?uncap_first}Bean){
			return ${className?uncap_first}Mapper.delete${className}(${className?uncap_first}Bean)>0;
		}
      
}